package myfirstgrailsproject

import org.hsqldb.Session

/**
 * This class is a data-holder - this is what
 * we store in the database.
 *
 * @author zach
 *
 */
class Exercise {

	String exerciseName;
	Course course;
	public static enum TeamType {RANDOM, SELF_SELECT, INDIVIDUAL};
	Date startDate;
	Date endDate;
	TeamType teamType;
	int maxSize;
  Hashtable studentGrades = new Hashtable();
	int exerciseWeight;

	//These are database relationships
	static belongsTo = [course: Course]
	static hasMany = [teams:Team, users:User]


	static constraints = {
		exerciseName(nullable:false, blank:false);
		course(nullable:false, blank:false);
		teamType(display:true, blank:false, nullable:false);
		startDate(display:true, blank:false, nullable:false, validator: {return (it >= new Date()-1)});
		endDate(display:true, blank:false, nullable:false, validator: {return (it > new Date())});
		maxSize(display:true, blank:false, nullable:false, validator: {return (it > 0)});
    exerciseWeight(display:true, blank:false, nullable:false, validator: {return (it > 0)});

	}

	String toString(){
		return exerciseName;
	}



}
